package com.service.impl;

import com.dao.AccountDao;
import com.pojo.Account;
import com.service.AccountService;
import com.service.TransRecondService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AccountServiceImpl implements AccountService {
    @Autowired
    TransRecondService transRecondService;
    @Autowired
    AccountDao accountDao;
    @Override
    public Account findById(Integer id) {
        return accountDao.findById(id);
    }

    @Override
    public void transMoney(int inId, int outId, int money) {
        //记录转账的记录
        transRecondService.log(inId,outId,money);
        //先把钱从原账号转出，再把钱转入到要转入的账户中
        accountDao.outMoney(outId,money);
        int i=1/0;//引入异常，模拟转账过程中出现的事故
        accountDao.inMoney(inId,money);
    }
}
